using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.Plugin.Sns.Scene
{
	public class NetSceneSnsTagList : NetSceneBaseEx<SnsTagListRequest, SnsTagListResponse, SnsTagListRequest.Builder>
	{
		private const string TAG = "NetSceneSnsTagList";
		private const string SNS_TAGLIST_MD5 = "sns_taglist_md5";
		private static NetSceneSnsTagList _mInstance;
		public static NetSceneSnsTagList Instance
		{
			get
			{
				if (NetSceneSnsTagList._mInstance == null)
				{
					NetSceneSnsTagList._mInstance = new NetSceneSnsTagList();
				}
				return NetSceneSnsTagList._mInstance;
			}
		}
		public bool doScene(SnsTagListOpCode opCode)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.OpCode = (uint)opCode;
			this.mBuilder.TagListMd5 = ConfigMgr.getString("sns_taglist_md5", "");
			this.mSessionPack.mCmdID = 116;
			return base.endBuilder();
		}
		protected override void onFailed(SnsTagListRequest request, SnsTagListResponse response)
		{
			Log.smethod_1("NetSceneSnsTagList", "send request failed");
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_TAG_LIST_ERR, RetConst.MM_ERR_CLIENT, null);
		}
		protected override void onSuccess(SnsTagListRequest request, SnsTagListResponse response)
		{
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_TAG_LIST_ERR, ret, null);
				return;
			}
			ConfigMgr.setString("sns_taglist_md5", response.TagListMd5);
			List<SnsTagInfo> list = new List<SnsTagInfo>();
			using (IEnumerator<SnsTag> enumerator = response.ListList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SnsTag current = enumerator.get_Current();
					SnsTagInfo snsTagInfo = SnsInfoMgr.toSnsTagInfo(current);
					list.Add(snsTagInfo);
				}
			}
			StorageMgr.snsTag.updateList(list);
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_TAG_LIST_SUCCESS, null, null);
			ConfigMgr.setBool("HasRequestSnsGroupKey", true);
		}
	}
}
